package com.order.action;

import java.sql.Date;
import java.util.List;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
import com.order.entity.Goods;
import com.order.entity.Order;
import com.order.service.OrderService;

@SuppressWarnings("serial")
public class OrderAction extends ActionSupport {
	private Order order = null;
	private List<Goods> goodses = null;
	private int[] amounts = null;

	public List<Goods> getGoodses() {
		return goodses;
	}

	public void setGoodses(List<Goods> goodses) {
		this.goodses = goodses;
	}

	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}

	public int[] getAmounts() {
		return amounts;
	}

	public void setAmounts(int[] amounts) {
		this.amounts = amounts;
	}

	/**
	 * 订单信息准备
	 * @return
	 * @throws Exception
	 */
	public String orderPre() throws Exception {
		return "orderPre";
	}

	/**
	 * 将订单信息写入数据库
	 * @return
	 * @throws Exception
	 */
	public String order() throws Exception {
		order.setCreatetime(new Date(System.currentTimeMillis()));
		if (new OrderService().addOrder(order, goodses, amounts) > 0) {
			return "ordered";
		} 
		return Action.ERROR;
	}
	
	/**
	 * 订单信息查询
	 * @return
	 * @throws Exception
	 */
	public String find() throws Exception {
		order = new OrderService().findOrder(order.getId());
		return "find";
	}
}
